 

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bullet extends Actor
{
    private static Counter score;
    private static int speed = 10;
    
    public Bullet(Counter counter)
    {
        GreenfootImage bulletImg = getImage();
        bulletImg.scale(bulletImg.getWidth()/5, bulletImg.getHeight()/5);
        score = counter;
    }
    
    /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        leaveWorld();
        if (getWorld() != null) {
            hitAsteroid();
        }
        if (getWorld() != null) { 
            vertMove();
        }
    }   
    
    public void hitAsteroid() 
    {
        Actor asteroid = getOneIntersectingObject(Asteroid.class);
        if (asteroid != null) 
        {
            getWorld().removeObject(asteroid);
            getWorld().removeObject(this);
            Greenfoot.playSound("sounds/bomb-03.wav");
            score.add(10);
        }
    }
    
    public void vertMove()
    {
        setLocation(getX(),getY()-speed);
    }
    
    public void leaveWorld()
    {
        if (getY() == 0) {
            getWorld().removeObject(this);
        }
    }
}
